//
//  LiuBaseViewController.swift
//  LiuWeiBo
//
//  Created by 刘晓晨 on 2017/3/27.
//  Copyright © 2017年 刘晓晨. All rights reserved.
//

import UIKit

class LiuBaseViewController: UITableViewController {
    
    init() {
        super.init(style: .grouped)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //判断是否注册
    lazy var isLogin:Bool = {
        let login = LiuUserAccountViewModel.sharedUserAccountViewModel.isSuccessToken
        return login!
    }()
    
    var visitorView:LiuVisitorView?
    
    //自定义view
    override func loadView() {
        if isLogin {
            super.loadView()
        } else {
            
            //自定义视图
            visitorView = LiuVisitorView()
            visitorView?.loginDelegate = self
            view = visitorView
            
            //没有登录设置导航栏按钮
            setupUI()
        }

    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    func setupUI() {
        //添加左右的barbuttonitem
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(titleStr: "注册", andTarget: self, action: #selector(leftItemAction))
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(titleStr: "登陆", andTarget: self, action: #selector(right))
        
    }
    
    func leftItemAction() {
        pushViewController()
    }
    func right() {
        pushViewController()
    }
    
    //push登陆界面
    func pushViewController() {
        let loginVc = LiuLoginViewController()
        
        let nav = LiuNavigationController(rootViewController: loginVc)
        
        present(nav, animated: true, completion: nil)
    }
    
    //修改行间距
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0.01
    }
    
    

}


extension LiuBaseViewController:LiuVisitorViewDelegate {
    
    //实现按钮点击的代理方法
    func didLoginAction() {
        self.pushViewController()
    }
}





